package com.pbking.facebook.delegates.users
{
	import com.pbking.facebook.Facebook;
	import com.pbking.facebook.FacebookSessionType;
	import com.pbking.facebook.delegates.FacebookDelegate;
	
	/**
	 * For Web applications, you must pass either the ID of the user on whose 
	 * behalf you're making this call or the session key for that user, but not both. 
	 * If you don't specify a user with the uid parameter, 
	 * then that user whose session it is will be the target of the call.  
	 * 
	 * However, if your application is a desktop application, 
	 * you must pass a valid session key for security reasons. 
	 * Do not pass a uid parameter. 
	 * 
	 * http://wiki.developers.facebook.com/index.php/Users.hasAppPermission
	 */ 
	public class HasAppPermissionDelegate extends FacebookDelegate
	{
		/**
		 * String identifier for the extended permission that is being checked for. 
		 * Must be one of status_update, create_listing, or photo_upload.
		 */
		public var extendedPermission:String;
		public var uid:String;
		public var hasPermission:Boolean;
		
		/**
		 * @param uid (optional) The user ID of the user whose permissions you are checking. If this parameter is not specified, then it defaults to the session user.
		 * Note: This parameter applies only to Web applications and is required by them only if the session_key is not specified. Facebook ignores this parameter if it is passed by a desktop application. 
		 */
		public function HasAppPermissionDelegate(facebook:Facebook, extendedPermission:String, uid:String=null)
		{
			super(facebook);
			
			if ((FacebookSessionType.WEB == facebook.sessionType) && uid) {
				fbCall.useSession = false;
			}
			
			this.extendedPermission = extendedPermission;
			
			fbCall.setRequestArgument("ext_perm", extendedPermission);
			if (uid) { // optional argument 
				fbCall.setRequestArgument("uid", uid);
				this.uid = uid; 
			} 
			fbCall.post("facebook.users.hasAppPermission");
		}
		
		override protected function handleResult(result:Object):void
		{
			hasPermission = Boolean(result);

		}
		
	}
}